home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / MPEG / AMPDecoder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  4.7 KB  |  185 lines

  1. /* 
  2.  *  AMPDecoder.h
  3.  *
  4.  *  Code from
  5.  *            NekoAmp 1.3 decoder by Avery Lee
  6.  *
  7.  *  FlasKMPEG
  8.  *    Copyright (C) Alberto Vigata - January 2000
  9.  *
  10.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  11.  *    
  12.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  13.  *  it under the terms of the GNU General Public License as published by
  14.  *  the Free Software Foundation; either version 2, or (at your option)
  15.  *  any later version.
  16.  *   
  17.  *  FlasKMPEG is distributed in the hope that it will be useful,
  18.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  *  GNU General Public License for more details.
  21.  *   
  22.  *  You should have received a copy of the GNU General Public License
  23.  *  along with GNU Make; see the file COPYING.  If not, write to
  24.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  25.  *
  26.  */
  27.  
  28. #ifndef f_AMPLIB_AMPDECODER_H
  29. #define f_AMPLIB_AMPDECODER_H
  30.  
  31. #include "IAMPDecoder.h"
  32. #include "AMPBitstream.h"
  33.  
  34. #define SBLIMIT (32)
  35. #define SSLIMIT (18)
  36.  
  37. struct gr_info_s {
  38.     unsigned part2_3_length;
  39.     unsigned big_values;
  40.     unsigned global_gain;
  41.     unsigned scalefac_compress;
  42.     unsigned window_switching_flag;
  43.     unsigned block_type;
  44.     unsigned mixed_block_flag;
  45.     unsigned table_select[3];
  46.     unsigned subblock_gain[3];
  47.     unsigned region0_count;
  48.     unsigned region1_count;
  49.     unsigned preflag;
  50.     unsigned scalefac_scale;
  51.     unsigned count1table_select;
  52. };
  53.  
  54. typedef struct {
  55.     unsigned main_data_begin;
  56.     unsigned private_bits;
  57.     struct {
  58.         unsigned scfsi[4];
  59.         struct gr_info_s gr[2];
  60.         } ch[2];
  61.     } III_side_info_t;
  62.  
  63. typedef struct III_scalefac1_t {
  64.     int l[23];            /* [cb] */
  65.     int s[3][13];         /* [window][cb] */
  66.     } III_scalefac_t[2];  /* [ch] */
  67.  
  68. class AMPDecoder : public IAMPDecoder, AMPBitstream {
  69. public:
  70.     AMPDecoder();
  71.     ~AMPDecoder();
  72.  
  73.     void Destroy();
  74.  
  75.     char *    GetAmpVersionString();
  76.     void    Init();
  77.     void    setSource(IAMPBitsource *pSource);
  78.     void    setDestination(short *psDest);
  79.     long    getSampleCount();
  80.     void    getStreamInfo(AMPStreamInfo *pasi);
  81.     char *    getErrorString(int err);
  82.     void    Reset();
  83.     void    ReadHeader();
  84.     void    PrereadFrame();
  85.     bool    DecodeFrame();
  86.  
  87. private:
  88.     float    window[2][512];
  89.     float    prevblck[2][SBLIMIT][SSLIMIT];
  90.     int        winptr;
  91.     short *    psDest;
  92.     long    lSampleCount;
  93.  
  94.     unsigned char *l3bitptr;
  95.     int        l3bitidx;
  96.  
  97.     long    frame_size;
  98.  
  99.     int        bitrate;
  100.     int        frequency;
  101.     int        br_index;
  102.     int        sr_index;
  103.     int        is_mpeg2;
  104.     bool    is_errorprotected;
  105.     bool    is_padded;
  106.     bool    is_extended;
  107.     bool    is_copyrighted;
  108.     bool    is_original;
  109.     int        layer;
  110.     int        mode;
  111.     int        mode_ext;
  112.     int        channels;
  113.     int        emphasis;
  114.  
  115.     III_side_info_t        sideinfo;
  116.     int        sideinfo_size;
  117.  
  118.     int        slen[4];                // MPEG-2 layer 3
  119.     const int *    scale_block_indexes;    // MPEG-2 layer 3
  120.  
  121.     static    int init_count;
  122.  
  123.     static    signed char group3[31][3];
  124.     static    signed char group5[127][3];
  125.     static    signed char group9[1023][3];
  126.     static    signed char (*group_tbls[3])[3];
  127.  
  128.     static    void Initialize();
  129.     static    void Deinitialize();
  130.  
  131.     void    L2_PrereadFrame();
  132.     bool    L2_DecodeFrame();
  133.  
  134.     int        L3_GetBits(int bits);
  135.     void    L3_GetSideInfo();
  136.     void    L3_PrereadFrame();
  137.     bool    L3_DecodeFrame();
  138.  
  139.     void    L3_GetScaleFactors1(III_scalefac_t *scalefac, int gr, int ch);
  140.     void    L3_GetScaleFactors2(III_scalefac_t *scalefac, int ch);
  141.  
  142.     int        L3_HuffmanDecode(long int is[SBLIMIT*SSLIMIT],
  143.                             int ch,
  144.                             int gr,
  145.                             int part2_start);
  146.     int        L3_DequantizeSample(long int is[SBLIMIT*SSLIMIT],
  147.                                 float xr[SBLIMIT*SSLIMIT],
  148.                                 const III_scalefac1_t *scalefac,
  149.                                 struct gr_info_s *gr_info,
  150.                                 int ch, int limit);
  151.     int        L3_Stereo(
  152.                     float lr[2][SBLIMIT*SSLIMIT],
  153.                     const III_scalefac_t *scalefac,
  154.                     struct gr_info_s *gr_info,
  155.                     int nz0, int nz1);
  156.  
  157.     void    L3_Reorder (float xr[SBLIMIT*SSLIMIT],
  158.                 float ro[SBLIMIT*SSLIMIT],
  159.                 struct gr_info_s *gr_info);
  160.  
  161.     void    L3_Antialias(float xr[SBLIMIT][SSLIMIT],
  162.                         struct gr_info_s *gr_info);
  163.  
  164.     void    L3_Hybrid(float fsIn[SBLIMIT][SSLIMIT],
  165.                 float fsOut[SSLIMIT][SBLIMIT],
  166.                 int ch,
  167.                 struct gr_info_s *gr_info,
  168.                 int nonzero_entries);
  169.  
  170.     void    L3_GetHuffmanBig(int table_id, long *is, int count) throw();
  171.     int        L3_GetHuffmanCount1_32(long *is, int i, int bit_threshold) throw();
  172.     int        L3_GetHuffmanCount1_33(long *is, int i, int bit_threshold) throw();
  173.  
  174.     void    polyphase(float *band_l, float *band_r, short *samples, bool invert_odd);
  175. //    void    polyphase_single(float *band, int ch, short *samples);
  176.     void    polyphase_retract(int amount);
  177. };
  178.  
  179. #define MODE_STEREO            (0)
  180. #define    MODE_JOINTSTEREO    (1)
  181. #define    MODE_DUALCHANNEL    (2)
  182. #define MODE_MONO            (3)
  183.  
  184. #endif
  185.